﻿using System;

namespace ebc.message.contract {
    public delegate void Request<TInput, TOutput>(TInput message, Action<TOutput> processResult);

    public static class RequestExtension {

        public static RequestContinuation<TOutput> Request<TInput, TOutput>(
            this Request<TInput,TOutput> fireEvent, TInput msg) {
            return new RequestContinuation<TOutput>(processResult => fireEvent(msg, processResult));
        }

        public class RequestContinuation<TOutput> {
            private readonly Action<Action<TOutput>> fireEvent;

            public RequestContinuation(Action<Action<TOutput>> fireEvent) {
                this.fireEvent = fireEvent;
            }

            public void Receive(Action<TOutput> processResult) {
                fireEvent(processResult);
            }
        }
    }
}
